{{extend name="shared/layout" /}
{block name="title"}修改课程{/block}
{block name="css"}
    <link href="/static/sys/css/appmsg.css" rel="stylesheet" />
    <link href="/static/sys/css/skin_0.css" rel="stylesheet" />
{/block}
{block name="javascript"}
    <script type="text/javascript" src="/static/plugins/layer/layer.min.js" ></script>
    <script type="text/javascript" src="/static/plugins/layer/laydate-v5.0.7/laydate.js" ></script>
    <script type="text/javascript">
         $(document).ready(function () {
            $("#ok").bind("click", Save);
            $("#cancel").bind("click", function () {
                parent.layer.close(parent.layer_edit_index);
            });
            $(".cb-enable").click(function () {
                var parent = $(this).parents('.onoff');
                $('.cb-disable', parent).removeClass('selected');
                $(this).addClass('selected');
                $('.checkbox', parent).attr('checked', true);
            });
            $(".cb-disable").click(function () {
                var parent = $(this).parents('.onoff');
                $('.cb-enable', parent).removeClass('selected');
                $(this).addClass('selected');
                $('.checkbox', parent).attr('checked', false);
            });
            layui.use(['laydate'], function(){
                laydate.render({elem: '#txtstart_time',type: 'time'});
                laydate.render({elem: '#txtend_time',type: 'time'});
            });
         })

         function Save() {
            layui.use(['layer'], function(){
                var k = 0;
                var replydata = {};
                switch($('select[name="selReplyType"]').val()){
                    case "1":
                        var replytxt = $('#txtReplyText').val();
                        replydata ={ type:1,replydata:replytxt };
                        break;
                    case "2":
                        var groupid = $("#dvRpImageText input[name=hdImageTextId]").val();
                        replydata = { type:2,replydata:groupid };
                        break;
                    case "3":
                        var groupid = $("#dvRpImage input[name=hdImageId]").val();
                        replydata = { type:3,replydata:groupid };
                        break;
                }

                var keywords = $("#txtkeywords").val();
                if (keywords.length == 0) {                
                    layer.tips('此项不能为空！', 'input[name=keywords]', { tips: [2, '#78BA32'] });
                    return false;
                }
                var remark = $("#txtremark").val();            
                var isopen = $("input:radio:checked").val();
                var replytext = encodeURIComponent(JSON.stringify(replydata));            
                var load_index = layer.load(0, { shade: false });
                $.ajax({
                    type: "post",
                    url: "{:url('customer/editkeyreply')}?t=" + new Date(),
                    data: { id: {$data.id} ,reply_data : replytext, isopen : isopen, keywords : keywords ,remark : remark},
                    dataType: "json",
                    success: function (result) {
                        layer.close(load_index);
                        if (result.code == 0) {
                            layer.alert('修改成功！', function () {
                                if (typeof (parent.initTable) == "function")
                                    parent.initTable();
                                parent.layer.close(parent.layer_edit_index)
                            });
                        } else {
                            layer.alert(result.msg);
                        }
                    }
                });
            });
        }

        var layer_sel_image_text_index;
        function openImageText(idx){
            layui.use(['layer'], function(){
                layer_sel_image_text_index = layer.open({
                    type: 2,
                    title: "选择图文分组",
                    shadeClose: true,
                    shade: false,
                    area:['80%', '90%'],
                    content:["{:url('customer/selimagetextgroup')}","no"]
                })
            })
        }

        var layer_sel_image_index;
        function openImage(idx){
            layui.use(['layer'], function(){
                layer_sel_image_index = layer.open({
                    type: 2,
                    title: "选择图片分组",
                    shadeClose: true,
                    shade: false,
                    area:['80%', '90%'],
                    content:["{:url('customer/selimagegroup')}","no"]
                })
            })
        }

        function changeReplyType(obj){
            switch(obj.value){
                case "1":
                    $("#dvRpImageText").hide();
                    $("#dvRpImage").hide();
                    $("#txtReplyText").show();
                    break;
                case "2":
                    $("#dvRpImageText").show();
                    $("#dvRpImage").hide();
                    $("#txtReplyText").hide();
                    break;
                case "3":
                    $("#dvRpImage").show();
                    $("#dvRpImageText").hide();
                    $("#txtReplyText").hide();
                    break;
            }
        }

        function select_result(d){            
            
            $("#dvRpImageText lable").remove();
            $("input[name=hdImageTextId]").remove();
            var html = "<input type=\"hidden\" name=\"hdImageTextId\" value=\"" + d.id + "\" /><lable>"+d.title+"</lable>";
            $("#dvRpImageText").append(html);
            layer.close(layer_sel_image_text_index);
        
        }
        
        function sel_imagegroup_result(d){
            var html = "";            
            
            $("#dvRpImage lable").remove();
            $("input[name=hdImageId]").remove();
            var html = "<input type=\"hidden\" name=\"hdImageId\" value=\"" + d.id + "\" /><lable>"+d.name+"</lable>";
            $("#dvRpImage").append(html);
            layer.close(layer_sel_image_index);
        
        }
    </script>
{/block}
{block name="content"}
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <form method="post" class="form-horizontal">                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">是否开启<span style="color:red;">(*)</span>:</label>
                                <div class="col-sm-4 onoff">
                                    <label for="isopen1" class="cb-enable {if condition='$data.isopen eq 1'}selected{/if}"><span>是</span></label>
                                    <label for="isopen0" class="cb-disable {if condition='$data.isopen eq 0'}selected{/if}"><span>否</span></label>
                                    <input id="isopen1" name="isopen" value="1" {if condition="$data.isopen eq 1"}checked="checked"{/if} type="radio">
                                    <input id="isopen0" name="isopen" value="0" {if condition="$data.isopen eq 0"}checked="checked"{/if} type="radio">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">回复关键字<span style="color:red;">(*)</span>：</label>
                                <div class="col-sm-4">
                                    <input type="text" name="keywords" id="txtkeywords" value="{$data.keywords}" class="form-control" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">备注</span>：</label>
                                <div class="col-sm-4">
                                    <textarea class="form-control diff-textarea" style="height:120px;" id="txtremark" name="remark" placeholder="备注内容">{$data.remark}</textarea>
                                </div>
                            </div>
                            <div id="replykey" class="hr-line-dashed"></div>
                            {$html}
                            <div id="replykey" class="hr-line-dashed"></div>                            
                            <div class="form-group" style="text-align:center;">                                
                                <button class="btn btn-primary" id="ok" type="button">提交</button>                      <button class="btn btn-white" id="cancel" type="button">取消</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>        
{/block}